package com.alingrad.android.test.cyborghuman;

import javax.microedition.khronos.opengles.GL10;

import com.alingrad.android.froyoengine.tree.FixedSizeObjectManager;

public class JumpObstacleManager extends FixedSizeObjectManager {
	private JumpObstaclePool mJumpPool;
	
	private long mTimeCounter; 
	
	@Override
	public void load(GL10 gl) {
		mJumpPool.load(gl);
	}
	
	public JumpObstacleManager() {
		super();
		mJumpPool = new JumpObstaclePool(16);
		mTimeCounter = 0;
	}

	@Override
	public void update(long delta) {
		super.update(delta);

		mTimeCounter += delta;
		if (mTimeCounter > 4000) { 
			JumpObstacle obstacle = mJumpPool.allocate();
			obstacle.initialize(1000);
			addNode(obstacle);
			mTimeCounter -= 4000;
		}
		
		for (int i = 0; i < mObjects.size();) {
			if (!mObjects.get(i).isAlive())
				mJumpPool.release((JumpObstacle)mObjects.remove(i));
			else
				i++;
		}
	}
}
